﻿#include <iostream>
#include <windows.h>
using namespace std;
void  main(void) {

    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    TCHAR szCommandLine[] = TEXT("NOTEPAD");
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));

    if (!CreateProcess(NULL, szCommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
    {
        fprintf(stderr, "Createprocess Failed ");
    }

    int x;
    while (true) {
        cout << "请输入要选择的操作：\n0:销毁进程\n1:挂起进程\n2:激活进程\n3:退出\n";
        cin >> x;
        switch (x) {
        case 0:
            if (TerminateProcess(pi.hProcess, 0))
                cout << "销毁进程成功" << endl;
            else
                cout << "销毁失败" << endl;
            break;
        case 1:
            if (SuspendThread(pi.hThread))
                cout << "挂起进程成功" << endl;
            else
                cout << "挂起失败" << endl;
            break;
        case 2:
            if (ResumeThread(pi.hThread))
                cout << "激活进程成功" << endl;
            else
                cout << "激活失败" << endl;
            break;
        case 3:
            exit(0);
        default:
            cout << "选项不正确" << endl;
        }
    }
}
